package com.mccrea.pattern.command;


import java.util.ArrayList;
import java.util.List;

/**
 * @Classname TeleController
 * @Description Invoker 调用者
 * @Date 2021/5/18 0018 10:41
 * @Created by Mccrea_Gao
 */
public class TeleController {
    List<Command> historyCommand = new ArrayList<>();

    /**
     * 切换卫视
     * @param command
     */
    public void switchCommand(Command command) {
        historyCommand.add(command);
        command.execute();
    }

    /**
     * 返回命令
     */
    public void back() {
        if (historyCommand.isEmpty()) {
            return;
        }
        Command remove = historyCommand.remove(historyCommand.size() <= 2 ? 0 : historyCommand.size() - 2);
        remove.execute();
    }
}
